package fons.navigator.util.piccolo;

import java.awt.Color;
import java.awt.Paint;
import java.awt.Shape;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

import edu.umd.cs.piccolo.nodes.PPath;

/**
 * @author Ilya Boyandin
 */
public class PPaths {

  private PPaths() {
  }

  public static PPath rect(double x, double y, double w, double h) {
    return rect(x, y, w, h, Color.black, Color.white);
  }

  public static PPath rect(double x, double y, double w, double h, Paint stroke, Paint fill) {
    PPath rect = new PPath(new Rectangle2D.Double(x, y, w, h));
    rect.setPaint(fill);
    rect.setStrokePaint(stroke);
    return rect;
  }
  
  public static Shape createArrowShape(Point2D start, Point2D end, double veeLength, double angle) { 
		// Arrow settings. 
		double b = veeLength; 
		double theta = Math.toRadians(angle); 

		// Arrow Calculations. 
		double xs = start.getX(); 
		double ys = start.getY(); 
		double xe = end.getX(); 
		double ye = end.getY(); 
		double alpha = Math.atan2(ye - ys, xe - xs); 
		double dx1 = b * Math.cos(alpha + theta); 
		double dy1 = b * Math.sin(alpha + theta); 
		double dx2 = b * Math.cos(alpha - theta); 
		double dy2 = b * Math.sin(alpha - theta); 

		// Arrow Path. 
		GeneralPath path = new GeneralPath(); 
		path.moveTo(xs, ys); 
		path.lineTo(xe, ye); 
		path.lineTo(xe - dx1, ye - dy1); 
		path.moveTo(xe, ye); 
		path.lineTo(xe - dx2, ye - dy2); 
		return path; 
	} 

}
